use anyhow::Result;
use serde::Serialize;
use strum::{
    Display, EnumCount, EnumDiscriminants, EnumIs, EnumIter, EnumString, IntoEnumIterator,
    IntoStaticStr, VariantNames,
};

#[derive(
    Debug, EnumString, EnumCount, EnumDiscriminants, EnumIter, EnumIs, IntoStaticStr, VariantNames,
)]
#[allow(unused)]
enum MyEnum {
    A,
    B(String),
    C,
}

#[allow(unused)]
#[derive(Display, Debug, Serialize)]
enum Color {
    //to_string 大于serialize 如果to_string 定义了 serialize不生效
    //serialize 和serde的serialize无关
    #[strum(serialize = "redred", to_string = "red")]
    Red,
    Green {
        range: usize,
    },
    Blue(usize),
    Yellow,
    #[strum(to_string = "purple with {sat} saturation")]
    Purple {
        sat: usize,
    },
}

fn main() -> Result<()> {
    // MyEnum::VARIANTS.iter().for_each(|variant|{println!("{:?}", variant)});
    println!("{:?}", MyEnum::VARIANTS);
    MyEnum::iter().for_each(|variant| println!("{variant:?}"));
    let en = MyEnum::B("hello".to_string());
    println!("{:?}", en.is_b());
    let s: &'static str = en.into();
    println!("{s:?}");

    let red = Color::Red;
    let green = Color::Green { range: 10 };
    let blue = Color::Blue(20);
    let yellow = Color::Yellow;
    let purple = Color::Purple { sat: 30 };

    println!("red: {red}, green: {green}, blue: {blue}, yellow: {yellow}, purple: {purple}");

    let red_str = serde_json::to_string(&red)?;
    println!("{red_str}");

    Ok(())
}
